const app = getApp();
Component({
  options: {
    addGlobalClass: true,
  },
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    TabCur: 0,
    MainCur: 0,
    VerticalNavTop: 0,
    list: [],
    load: true,
  },
  attached() {
    wx.request({
      url: `${app.globalData.local_url}api/getGameLists`,
      data: {},
      method: 'GET',
      header: {
        'content-type': 'application/json',
      },
      success: (res) => {
        if (res.data.code === 200) {
          this.setData({
            list: res.data.data,
          });
        }
      }
    });
  },
  methods: {
    toinfo(e) {
      wx.navigateTo({
        url: `/pages/activity/info/info?id=${e.currentTarget.dataset.id}`
      });
    },
    tabSelect(e) {
      this.setData({
        TabCur: e.currentTarget.dataset.id,
        MainCur: e.currentTarget.dataset.id,
        VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50,
      });
    },
    verticalMain(e) {
      const { list } = this.data;
      const scrollTop = e.detail.scrollTop + 20;

      const currentTab = list.findIndex(item => scrollTop >= item.top && scrollTop < item.bottom);
      if (currentTab !== -1) {
        this.setData({
          VerticalNavTop: (currentTab - 1) * 50,
          TabCur: currentTab,
        });
      }
    }
  }
});
